package org.sems.sems.service.impl;

import org.sems.sems.Mapper.DcwjkMapper;
import org.sems.sems.entity.Dcwjhdk;
import org.sems.sems.entity.Dcwjk;
import org.sems.sems.service.DcwjkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.sems.sems.Mapper.DcwjhdkMapper;
import java.util.HashMap;
import java.util.Map;

@Service
public class DcwjkServiceImpl implements DcwjkService {
    @Autowired
    private DcwjkMapper dcwjkMapper;

    /**
     * @return
     */
    @Override
    public Map<String, Object> getDcwjk(int dcwjid) {
        Map<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("msg", "success");
        result.put("data", dcwjkMapper.getDcwjkById(dcwjid));
        return result;
    }

    public Map<String, Object> getDcwjkList(String yhm, int fbzsfdm) {
        Map<String, Object> result = new HashMap<>();
        try {
            result.put("code", 200);
            result.put("result", true);
            result.put("msg", "success");
            result.put("data", dcwjkMapper.getDcwjkByFBZ(yhm, fbzsfdm));
        } catch (Exception e) {
            e.printStackTrace();
            result.put("code", 500);
            result.put("msg", "server error");
            result.put("result", false);
        }
        return result;
    }

    @Autowired
    private DcwjhdkMapper dcwjhdkMapper;

    /**
     * @param dcwjhdk
     * @return
     */
    @Override
    public Map<String, Object> addDcwjkAnswer(Dcwjhdk dcwjhdk) {
        Map<String, Object> result = new HashMap<>();
        try {
            if (dcwjhdkMapper.insertDcwjhdk(dcwjhdk) > 0) {
                result.put("code", 200);
                result.put("msg", "success");
                result.put("data", dcwjhdk);
                result.put("result", true);
            } else {
                result.put("code", 504);
                result.put("msg", "database error");
                result.put("data", null);
                result.put("result", false);
            }
        } catch (Exception e) {
            e.printStackTrace();
            result.put("code", 500);
            result.put("msg", "server error");
            result.put("result", false);
        }
        return result;
    }

    /**
     * @param dcwjid
     * @return
     */
    @Override
    public Map<String, Object> getDcwjkAnswer(int dcwjid) {
        Map<String, Object> result = new HashMap<>();
        try {
            result.put("code", 200);
            result.put("result", true);
            result.put("msg", "success");
            result.put("data",dcwjhdkMapper.getDcwjhdkByDcwjid(dcwjid));
        } catch (Exception e) {
            e.printStackTrace();
            result.put("code", 500);
            result.put("msg", "server error");
            result.put("result", false);
        }
        return result;
    }

    /**
     * @param yhm
     * @return
     */
    @Override
    public Map<String, Object> getDcwjkAnswerList(String yhm) {
        Map<String, Object> result = new HashMap<>();
        try {
            result.put("code", 200);
            result.put("result", true);
            result.put("msg", "success");
            result.put("data",dcwjhdkMapper.getDcwjhdkByYhmStudent(yhm));
        } catch (Exception e) {
            e.printStackTrace();
            result.put("code", 500);
            result.put("msg", "server error");
            result.put("result", false);
        }
        return result;
    }

    /**
     * @param yhm
     * @return
     */
    @Override
    public Map<String, Object> getDcwjkAnswerListTeacher(String yhm) {
        Map<String, Object> result = new HashMap<>();
        try {
            result.put("code", 200);
            result.put("result", true);
            result.put("msg", "success");
            result.put("data",dcwjhdkMapper.getDcwjhdkByYhmTeacher(yhm));
        } catch (Exception e) {
            e.printStackTrace();
            result.put("code", 500);
            result.put("msg", "server error");
            result.put("result", false);
        }
        return result;
    }

    /**
     * @param dcwjk
     * @return
     */
    @Override
    public Map<String, Object> addDcwjk(Dcwjk dcwjk) {
        Map<String, Object> result = new HashMap<>();
        try {
            if (dcwjkMapper.insertDcwjk(dcwjk) > 0) {
                result.put("code", 200);
                result.put("msg", "success");
                result.put("data", dcwjk);
                result.put("result", true);
            } else {
                result.put("code", 504);
                result.put("msg", "database error");
                result.put("data", null);
                result.put("result", false);
            }
        } catch (Exception e) {
            e.printStackTrace();
            result.put("code", 500);
            result.put("msg", "server error");
            result.put("result", false);
        }
        return result;
    }
}
